package cn.ren.hai.base.controller;
import cn.ren.hai.core.entity.QueryPage;
import cn.ren.hai.core.response.ResponseBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ren.hai.base.service.RhFileService;
import cn.ren.hai.base.entity.RhFile;;
import cn.ren.hai.core.entity.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;

/**
* <p>
    * 文件 前端控制器
    * </p>
*
* @author wangdao
* @since 2022-01-07
*/
@RestController
@RequestMapping("/api/base/rh-file")
    public class RhFileController {


    private final  RhFileService rhFileService;

    @Autowired
    public RhFileController(RhFileService rhFileService) {
        this.rhFileService = rhFileService;
    }

    /**
    * 查询分页数据
    */
    @ApiOperation(value = "查询分页数据")
    @PostMapping(value = "/getList")
    public ResponseBean<PageInfo<RhFile>> getList(@RequestBody QueryPage<RhFile> page) {

        return new ResponseBean<>(rhFileService.list(page));
    }


    /**
    * 根据id查询
    */
    @ApiOperation(value = "根据id查询数据")
    @GetMapping(value = "/getById")
    public ResponseBean<RhFile> getById(@RequestParam("id") Serializable id){
        return new ResponseBean<>(rhFileService.getById(id));
    }

    /**
    * 新增
    */
    @ApiOperation(value = "新增/修改 数据")
    @PostMapping(value = "/saveUpdate")
    public ResponseBean<Boolean> saveUpdate(@RequestBody RhFile rhFile){
        return new ResponseBean<>(rhFileService.saveOrUpdate(rhFile));
    }

    /**
    * 删除
    */
    @ApiOperation(value = "删除数据")
    @DeleteMapping(value = "/del")
    public ResponseBean<Boolean> delete(@RequestParam("id") Serializable id){
        return new ResponseBean<>(rhFileService.removeById(id));
    }
}
